﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace EWDTAssignment
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string code = Convert.ToString(Session["verifyCode"]);
            if (this.IsValid)
            {
                if (code == verificationTbx.Text)
                {
                    App_Code.Account a = new App_Code.Account();
                    a.Username = UsernameTbx.Text;
                    a.Password = PasswordTbx.Text;
                    
                    App_Code.Account account = new App_Code.Account();
                    account.AccountID = 0;
                    account = App_Code.Account.Login(a);
                    if (account.AccountID != 0)
                    {
                        Session["AccountID"] = account.AccountID;
                        Session["accType"] = account.Type;
                        Response.Redirect("index.aspx");
                    }
                }
                else
                {
                    VerificationLabel.Text = "Invalid verify code";
                }
            }
        }
    }
}